package com.example.ourradio;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class Utils {
	public static final String AUTHENTICATION_ENDPOINT = 
		"http://www.10.0.0.7.xip.io:3000/auth/google/login";
	public static final String FEED_URL = 
		"http://www.10.0.0.7.xip.io:3000/app/feed";	   
	public static final String SPEECH_URL = 
		"http://www.10.0.0.7.xip.io:3000/app/speech";	   
	public static final String UPLOAD_URL = 
		"http://www.10.0.0.7.xip.io:3000/upload";	
	public static final String LOGOUT_URL = 
		"http://www.10.0.0.7.xip.io:3000/auth/google/logout";	   
			
	public final static String PREFS_NAME = "com.example.ourradio";		
	public final static String OAUTH_TOKEN = "com.example.ourradio.oauth_token";
	public final static String STATE_PLAY_ORDER = 
		"com.example.ourradio.STATE_PLAY_ORDER";		
	
	public static String addAccessTokenToUrl(String url, String accessToken){
	    if(!url.endsWith("?"))
	        url += "?";

	    List<NameValuePair> params = new LinkedList<NameValuePair>();
	    params.add(new BasicNameValuePair("access_token", accessToken));
	    String paramString = URLEncodedUtils.format(params, "utf-8");

	    url += paramString;
	    return url;
	}

	public static void logout(String accessToken){
		try {
			// defaultHttpClient
			DefaultHttpClient httpClient = new DefaultHttpClient();
			HttpGet httpGet = 
				new HttpGet(addAccessTokenToUrl(LOGOUT_URL, accessToken));
        
			@SuppressWarnings("unused")
			HttpResponse httpResponse = httpClient.execute(httpGet);
	
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}	
}
